package org.jeecg.modules.online.cgreport.service.impl;

import cn.hutool.core.util.ReUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.lang.invoke.SerializedLambda;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import net.sf.jsqlparser.JSQLParserException;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.TuringBootException;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.system.vo.DynamicDataSourceModel;
import org.jeecg.common.util.SqlInjectionUtil;
import org.jeecg.common.util.dynamic.db.DataSourceCachePool;
import org.jeecg.common.util.dynamic.db.DynamicDBUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.common.util.sqlparse.JSqlParserUtils;
import org.jeecg.common.util.sqlparse.vo.SelectSqlInfo;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.online.cgform.enums.DataBaseEnum;
import org.jeecg.modules.online.cgform.utils.CgformUtil;
import org.jeecg.modules.online.cgform.utils.OnlSlotRender;
import org.jeecg.modules.online.cgreport.constant.CgReportConstant;
import org.jeecg.modules.online.cgreport.entity.OnlCgreportHead;
import org.jeecg.modules.online.cgreport.entity.OnlCgreportItem;
import org.jeecg.modules.online.cgreport.entity.OnlCgreportParam;
import org.jeecg.modules.online.cgreport.mapper.OnlCgreportHeadMapper;
import org.jeecg.modules.online.cgreport.model.OnlCgreportModel;
import org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService;
import org.jeecg.modules.online.cgreport.service.IOnlCgreportItemService;
import org.jeecg.modules.online.cgreport.service.IOnlCgreportParamService;
import org.jeecg.modules.online.cgreport.util.CgReportSqlFiledParseUtils;
import org.jeecg.modules.online.cgreport.util.CgReportSqlUtil;
import org.jeecg.modules.online.config.exception.DBException;
import org.jeecg.modules.online.config.p020b.OnlineFieldConfig;
import org.jeecg.modules.online.config.p022d.DbTableUtil;
import org.jeecg.modules.online.p002a.ConditionHandler;
import org.jeecg.modules.online.p002a.SqlParamsHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("onlCgreportHeadServiceImpl")
/* renamed from: org.jeecg.modules.online.cgreport.service.a.c */
/* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgreport/service/a/c.class */
public class OnlCgreportHeadServiceImpl extends ServiceImpl<OnlCgreportHeadMapper, OnlCgreportHead> implements IOnlCgreportHeadService {

    /* renamed from: b */
    private static final Logger f515b;
    @Autowired
    private IOnlCgreportParamService onlCgreportParamService;
    @Autowired
    private IOnlCgreportItemService onlCgreportItemService;
    @Autowired
    private OnlCgreportHeadMapper mapper;
    @Autowired
    @Lazy
    private ISysBaseAPI sysBaseAPI;
    @Autowired
    private JeecgBaseConfig jeecgBaseConfig;

    /* renamed from: a */
    static final /* synthetic */ boolean f516a;

    /* renamed from: a */
//    private static /* synthetic */ Object m87a(SerializedLambda serializedLambda) {
//        String implMethodName = serializedLambda.getImplMethodName();
//        boolean z = true;
//        switch (implMethodName.hashCode()) {
//            case 1255404527:
//                if (implMethodName.equals("getFieldName")) {
//                    z = true;
//                    break;
//                }
//                break;
//            case 1731767923:
//                if (implMethodName.equals("getCgrheadId")) {
//                    z = true;
//                    break;
//                }
//                break;
//            case 1845597416:
//                if (implMethodName.equals("getIsSearch")) {
//                    z = false;
//                    break;
//                }
//                break;
//        }
//        switch (z) {
//            case false:
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportItem") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
//                    return (v0) -> {
//                        return v0.getIsSearch();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportItem") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/Integer;")) {
//                    return (v0) -> {
//                        return v0.getIsSearch();
//                    };
//                }
//                break;
//            case true:
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportParam") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportItem") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportParam") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportItem") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportItem") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportParam") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportItem") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportParam") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportItem") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportParam") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getCgrheadId();
//                    };
//                }
//                break;
//            case true:
//                if (serializedLambda.getImplMethodKind() == 5 && serializedLambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && serializedLambda.getFunctionalInterfaceMethodName().equals("apply") && serializedLambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && serializedLambda.getImplClass().equals("org/jeecg/modules/online/cgreport/entity/OnlCgreportItem") && serializedLambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
//                    return (v0) -> {
//                        return v0.getFieldName();
//                    };
//                }
//                break;
//        }
//        throw new IllegalArgumentException("Invalid lambda deserialization");
//    }

    static {
        f516a = !OnlCgreportHeadServiceImpl.class.desiredAssertionStatus();
        f515b = LoggerFactory.getLogger(OnlCgreportHeadServiceImpl.class);
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    public Map<String, Object> executeSelectSql(String sql, String onlCgreportHeadId, Map<String, Object> params) throws SQLException {
        String[] strArr;
        List<OnlCgreportItem> list;
        IPage<Map<String, Object>> selectPageByCondition;
        String str = null;
        try {
            str = DbTableUtil.getDatabaseType();
        } catch (DBException e) {
            e.printStackTrace();
        }
        LambdaQueryWrapper<OnlCgreportParam> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(OnlCgreportParam::getCgrheadId, onlCgreportHeadId);
        SqlParamsHandler sqlParamsHandler = new SqlParamsHandler(params, this.onlCgreportParamService.list(lambdaQueryWrapper));
        String sql2 = sqlParamsHandler.m534a(sql);
        Map<String, Object> selfSqlParams = sqlParamsHandler.getSelfSqlParams();
        HashMap hashMap = new HashMap(5);
        Page<Map<String, Object>> page = new Page<>(Integer.valueOf(oConvertUtils.getInt(params.get("pageNo"), 1)).intValue(), Integer.valueOf(oConvertUtils.getInt(params.get("pageSize"), 10)).intValue());
        LambdaQueryWrapper<OnlCgreportItem> lambdaQueryWrapper2 = new LambdaQueryWrapper();
        lambdaQueryWrapper2.eq(OnlCgreportItem::getCgrheadId, onlCgreportHeadId);
        List<String> arrayList = new ArrayList();
        for (String str2 : (String[]) params.keySet().toArray(new String[0])) {
            if (str2.startsWith(CgReportConstant.f499E)) {
                String substring = str2.substring(CgReportConstant.f499E.length());
                arrayList.add(substring);
                params.put(substring, params.get(str2));
            }
        }
        if (arrayList.size() > 0) {
            lambdaQueryWrapper2.in(OnlCgreportItem::getFieldName, arrayList);
            list = this.onlCgreportItemService.list(lambdaQueryWrapper2);
            if (list.size() < arrayList.size()) {
                boolean anyMatch2 = list.stream().anyMatch(onlCgreportItem -> {
                    return "id".equalsIgnoreCase(onlCgreportItem.getFieldName());
                });
                if (!anyMatch2) {
                    OnlCgreportItem onlCgreportItem2 = new OnlCgreportItem();
                    onlCgreportItem2.setFieldName("id");
                    onlCgreportItem2.setFieldType(CgReportConstant.f494z);
                    onlCgreportItem2.setSearchMode("single");
                    onlCgreportItem2.setIsSearch(1);
                    list.add(onlCgreportItem2);
                }
            } else {
                list.forEach(onlCgreportItem3 -> {
                    onlCgreportItem3.setIsSearch(1);
                });
            }
        } else {
            lambdaQueryWrapper2.eq(OnlCgreportItem::getIsSearch ,1);
            list = this.onlCgreportItemService.list(lambdaQueryWrapper2);
        }
        String sql3 = QueryGenerator.convertSystemVariables(sql2);
        ArrayList arrayList2 = new ArrayList();
        for (OnlCgreportItem onlCgreportItem4 : list) {
            arrayList2.add(new OnlineFieldConfig(onlCgreportItem4));
        }
        ConditionHandler conditionHandler = new ConditionHandler("jeecg_rp_temp.", str);
        String m564a = conditionHandler.m564a(arrayList2, params);
        Map<String, Object> sqlParams = conditionHandler.getSqlParams();
        if (ReUtil.contains(" order\\s+by ", sql3.toLowerCase()) && "SQLSERVER".equalsIgnoreCase(str)) {
            throw new TuringBootException("SqlServer不支持SQL内排序!");
        }
        String str3 = "select * from (" + sql3 + ") jeecg_rp_temp ";
        if (m564a.trim().length() > 0) {
            str3 = str3 + CgReportSqlUtil.f507a + m564a;
        }
        Object obj = params.get("column");
        if (obj != null) {
            String valueOf = String.valueOf(params.get("order"));
            String[] split = String.valueOf(obj).split(CgformUtil.f233E);
            for (int i = 0; i < split.length; i++) {
                split[i] = SqlInjectionUtil.getSqlInjectField(split[i]);
            }
            str3 = str3 + " order by jeecg_rp_temp." + String.join(" " + valueOf + ", jeecg_rp_temp.", split) + " " + valueOf;
        }
        SqlInjectionUtil.specialFilterContentForOnlineReport(str3);
        if (!selfSqlParams.isEmpty()) {
            sqlParams.putAll(selfSqlParams);
        }
        if (Boolean.valueOf(String.valueOf(params.get("getAll"))).booleanValue()) {
            List<Map<String, Object>> selectByCondition = this.mapper.selectByCondition(str3, sqlParams);
            selectPageByCondition = new Page<>();
            selectPageByCondition.setRecords(selectByCondition);
            selectPageByCondition.setTotal(selectByCondition.size());
        } else {
            selectPageByCondition = this.mapper.selectPageByCondition(page, str3, sqlParams);
        }
        hashMap.put("total", Long.valueOf(selectPageByCondition.getTotal()));
        hashMap.put("records", CgformUtil.m322d(selectPageByCondition.getRecords()));
        return hashMap;
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    public Map<String, Object> executeSelectSqlDynamic(String dbKey, String sql, Map<String, Object> params, String onlCgreportHeadId) {
        String str = (String) params.get("order");
        String str2 = (String) params.get("column");
        int i = oConvertUtils.getInt(params.get("pageNo"), 1);
        int i2 = oConvertUtils.getInt(params.get("pageSize"), 10);
        DynamicDataSourceModel cacheDynamicDataSourceModel = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
        if (ReUtil.contains(" order\\s+by ", sql.toLowerCase()) && "3".equalsIgnoreCase(cacheDynamicDataSourceModel.getDbType())) {
            throw new TuringBootException("SqlServer不支持SQL内排序!");
        }
        LambdaQueryWrapper<OnlCgreportParam> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(OnlCgreportParam::getCgrheadId, onlCgreportHeadId);
        SqlParamsHandler sqlParamsHandler = new SqlParamsHandler(params, this.onlCgreportParamService.list(lambdaQueryWrapper));
        String sql2 = sqlParamsHandler.m531b(sql);
        Map<String, Object> selfSqlParams = sqlParamsHandler.getSelfSqlParams();
        LambdaQueryWrapper<OnlCgreportItem> lambdaQueryWrapper2 = new LambdaQueryWrapper();
        lambdaQueryWrapper2.eq(OnlCgreportItem::getCgrheadId, onlCgreportHeadId);
        lambdaQueryWrapper2.eq(OnlCgreportItem::getIsSearch, 1);
        List<OnlCgreportItem> list = this.onlCgreportItemService.list(lambdaQueryWrapper2);
        String sql3 = QueryGenerator.convertSystemVariables(sql2);
        ArrayList arrayList = new ArrayList();
        for (OnlCgreportItem onlCgreportItem : list) {
            arrayList.add(new OnlineFieldConfig(onlCgreportItem));
        }
        ConditionHandler conditionHandler = new ConditionHandler("jeecg_rp_temp.", DataBaseEnum.getDataBaseNameByValue(cacheDynamicDataSourceModel.getDbType()));
        conditionHandler.setDaoType(ConditionHandler.f67a);
        String m564a = conditionHandler.m564a(arrayList, params);
        Map<String, Object> sqlParams = conditionHandler.getSqlParams();
        String str3 = "select * from (" + sql3 + ") jeecg_rp_temp ";
        if (m564a.trim().length() > 0) {
            str3 = str3 + CgReportSqlUtil.f507a + m564a;
        }
        String m95c = CgReportSqlUtil.m95c(str3);
        if (params.get("column") != null) {
            //str3 = str3 + " order by jeecg_rp_temp." + obj.toString() + " " + params.get("order").toString();
        }
        if (!selfSqlParams.isEmpty()) {
            sqlParams.putAll(selfSqlParams);
        }
        HashMap hashMap = new HashMap(5);
        hashMap.put("total", DynamicDBUtil.queryCount(dbKey, m95c, sqlParams).get("total"));
        hashMap.put("records", CgformUtil.m322d(CgReportSqlUtil.m98a(String.valueOf(params.get("getAll")), dbKey, str3, i, i2, sqlParams)));
        return hashMap;
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    @Transactional(rollbackFor = {Exception.class})
    @CacheEvict(value = {"sys:cache:online:rp"}, allEntries = true, beforeInvocation = true)
    public Result<?> editAll(OnlCgreportModel values) {
        OnlCgreportHead head = values.getHead();
        if (((OnlCgreportHead) super.getById(head.getId())) == null) {
            return Result.error("未找到对应实体");
        }
        super.updateById(head);
        LambdaQueryWrapper<OnlCgreportItem> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(OnlCgreportItem::getCgrheadId, head.getId());
        this.onlCgreportItemService.remove(lambdaQueryWrapper);
        LambdaQueryWrapper<OnlCgreportParam> lambdaQueryWrapper2 = new LambdaQueryWrapper();
        lambdaQueryWrapper2.eq(OnlCgreportParam::getCgrheadId,head.getId());
        this.onlCgreportParamService.remove(lambdaQueryWrapper2);
        for (OnlCgreportParam onlCgreportParam : values.getParams()) {
            onlCgreportParam.setCgrheadId(head.getId());
        }
        for (OnlCgreportItem onlCgreportItem : values.getItems()) {
            onlCgreportItem.setFieldName(onlCgreportItem.getFieldName().trim().toLowerCase());
            onlCgreportItem.setCgrheadId(head.getId());
        }
        this.onlCgreportItemService.saveBatch(values.getItems());
        this.onlCgreportParamService.saveBatch(values.getParams());
        return Result.ok("全部修改成功");
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    @Transactional(rollbackFor = {Exception.class})
    public Result<?> delete(String id) {
        if (super.removeById(id)) {
        	LambdaQueryWrapper<OnlCgreportItem> lambdaQueryWrapper = new LambdaQueryWrapper();
            lambdaQueryWrapper.eq(OnlCgreportItem::getCgrheadId, id);
            this.onlCgreportItemService.remove(lambdaQueryWrapper);
            LambdaQueryWrapper<OnlCgreportParam> lambdaQueryWrapper2 = new LambdaQueryWrapper();
            lambdaQueryWrapper2.eq(OnlCgreportParam::getCgrheadId, id);
            this.onlCgreportParamService.remove(lambdaQueryWrapper2);
        }
        return Result.ok("删除成功");
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    @Transactional(rollbackFor = {Exception.class})
    public Result<?> bathDelete(String[] ids) {
        for (String str : ids) {
            if (super.removeById(str)) {
            	LambdaQueryWrapper<OnlCgreportItem> lambdaQueryWrapper = new LambdaQueryWrapper();
                lambdaQueryWrapper.eq(OnlCgreportItem::getCgrheadId, str);
                this.onlCgreportItemService.remove(lambdaQueryWrapper);
                LambdaQueryWrapper<OnlCgreportParam> lambdaQueryWrapper2 = new LambdaQueryWrapper();
                lambdaQueryWrapper2.eq(OnlCgreportParam::getCgrheadId, str);
                this.onlCgreportParamService.remove(lambdaQueryWrapper2);
            }
        }
        return Result.ok("删除成功");
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    public List<String> getSqlFields(String sql, String dbKey) throws SQLException, DBException, JSQLParserException {
        List<String> m88a;
        if (StringUtils.isNotBlank(dbKey)) {
            m88a = m88a(sql, dbKey);
        } else {
            m88a = m88a(sql, null);
        }
        return m88a;
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    public List<String> getSqlParams(String sql) {
        if (oConvertUtils.isEmpty(sql)) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        Matcher matcher = Pattern.compile("\\$\\{\\w+\\}").matcher(sql);
        while (matcher.find()) {
            String group = matcher.group();
            arrayList.add(group.substring(group.indexOf("{") + 1, group.indexOf("}")));
        }
        return arrayList;
    }

    /* renamed from: a */
    private List<String> m88a(String str, String str2) throws SQLException, DBException, JSQLParserException {
        if (oConvertUtils.isEmpty(str)) {
            return null;
        }
        String trim = str.replace("[^><]=", CgReportConstant.f489u).trim();
        if (trim.endsWith(";")) {
            trim = trim.substring(0, trim.length() - 1);
        }
        String m100a = CgReportSqlUtil.m100a(QueryGenerator.convertSystemVariables(trim));
        SelectSqlInfo parseSelectSqlInfo = JSqlParserUtils.parseSelectSqlInfo(m100a);
        if (f516a || parseSelectSqlInfo != null) {
            if (this.jeecgBaseConfig.getFirewall() != null && this.jeecgBaseConfig.getFirewall().getDisableSelectAll().booleanValue() && parseSelectSqlInfo.isSelectAll()) {
                throw new TuringBootException("不允许使用 *");
            }
            Set<String> set = null;
            if (StringUtils.isNotBlank(str2)) {
                DynamicDataSourceModel cacheDynamicDataSourceModel = DataSourceCachePool.getCacheDynamicDataSourceModel(str2);
                if (ReUtil.contains(" order\\s+by ", m100a.toLowerCase()) && "3".equalsIgnoreCase(cacheDynamicDataSourceModel.getDbType())) {
                    throw new TuringBootException("SqlServer不支持SQL内排序!");
                }
                Map<String, Object> m99a = CgReportSqlUtil.m99a(str2, m100a);
                if (m99a == null) {
                    if (!m100a.contains("*")) {
                        try {
                            m99a = CgReportSqlFiledParseUtils.m103a(m100a);
                        } catch (Exception e) {
                        }
                    }
                    if (m99a == null) {
                        throw new TuringBootException("该报表sql没有数据");
                    }
                }
                set = m99a.keySet();
            } else {
                String databaseType = DbTableUtil.getDatabaseType();
                if (ReUtil.contains(" order\\s+by ", m100a.toLowerCase()) && "SQLSERVER".equalsIgnoreCase(databaseType)) {
                    throw new TuringBootException("SqlServer不支持SQL内排序!");
                }
                List records = this.mapper.executeParseSql(new Page<>(1L, 1L), m100a).getRecords();
                if (records.size() < 1) {
                    if (!m100a.contains("*")) {
                        try {
                            set = CgReportSqlFiledParseUtils.m103a(m100a).keySet();
                        } catch (Exception e2) {
                        }
                    }
                    if (set == null) {
                        throw new TuringBootException("该报表sql没有数据");
                    }
                } else {
                    set = ((Map) records.get(0)).keySet();
                }
            }
            if (set != null) {
                set.remove("ROW_ID");
            }
            return new ArrayList(set);
        }
        throw new AssertionError();
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    public Map<String, Object> queryCgReportConfig(String reportId) {
        HashMap hashMap = new HashMap(5);
        Map<String, Object> queryCgReportMainConfig = this.mapper.queryCgReportMainConfig(reportId);
        List<Map<String, Object>> queryCgReportItems = this.mapper.queryCgReportItems(reportId);
        List<OnlCgreportParam> queryCgReportParams = this.mapper.queryCgReportParams(reportId);
        if (DbTableUtil.m39a()) {
            hashMap.put(CgReportConstant.f469a, CgformUtil.m361a(queryCgReportMainConfig));
            hashMap.put(CgReportConstant.f470b, CgformUtil.m322d(queryCgReportItems));
        } else {
            hashMap.put(CgReportConstant.f469a, queryCgReportMainConfig);
            hashMap.put(CgReportConstant.f470b, queryCgReportItems);
        }
        hashMap.put(CgReportConstant.f471c, queryCgReportParams);
        return hashMap;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v36, types: [java.util.List] */
    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    @Deprecated
    public List<DictModel> queryDictSelectData(String sql, String keyword, int pageNo, int pageSize) {
        this.sysBaseAPI.dictTableWhiteListCheckBySql(sql);
        List arrayList = new ArrayList();
        Page<Map<String, Object>> page = new Page<>();
        page.setSearchCount(false);
        page.setCurrent(pageNo);
        page.setSize(pageSize);
        String sql2 = sql.trim();
        int lastIndexOf = sql2.lastIndexOf(";");
        if (lastIndexOf == sql2.length() - 1) {
            sql2 = sql2.substring(0, lastIndexOf);
        }
        QueryWrapper<?> queryWrapper = new QueryWrapper<>();
        if (keyword != null && !"".equals(keyword)) {
            String str = "%" + keyword + "%";
            queryWrapper.like("temp.value", str).or().like("temp.text", str);
        }
        List list = (List) ((OnlCgreportHeadMapper) this.baseMapper).selectPageBySql(page, sql2, queryWrapper).getRecords().stream().filter(map -> {
            return map != null;
        }).collect(Collectors.toList());
        if (list != null && list.size() != 0) {
            arrayList = JSON.parseArray(JSON.toJSONString(list), DictModel.class);
        }
        return arrayList;
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    @Cacheable(value = {"sys:cache:online:rp"}, key = "'column-v2-'+#code+'-'+#queryDict")
    public Map<String, Object> queryColumnInfo(String code, boolean queryDict) {
        HashMap hashMap = new HashMap(5);
        QueryWrapper<OnlCgreportItem> queryWrapper = new QueryWrapper();
        queryWrapper.eq("cgrhead_id", code).eq("is_show", 1).orderByAsc("order_num");
        List<OnlCgreportItem> list = this.onlCgreportItemService.list(queryWrapper);
        JSONArray jSONArray = new JSONArray();
        JSONArray jSONArray2 = new JSONArray();
        HashMap hashMap2 = new HashMap(5);
        boolean z = false;
        for (OnlCgreportItem onlCgreportItem : list) {
            JSONObject jSONObject = new JSONObject(4);
            jSONObject.put("id", onlCgreportItem.getId());
            jSONObject.put(CgformUtil.f298aR, onlCgreportItem.getFieldTxt());
            jSONObject.put("dataIndex", onlCgreportItem.getFieldName());
            jSONObject.put("fieldType", onlCgreportItem.getFieldType());
            jSONObject.put("align", CgformUtil.f291aK);
            jSONObject.put("sorter", "true");
            jSONObject.put("isTotal", onlCgreportItem.getIsTotal());
            jSONObject.put("groupTitle", onlCgreportItem.getGroupTitle());
            if (oConvertUtils.isNotEmpty(onlCgreportItem.getGroupTitle())) {
                z = true;
            }
            String fieldType = onlCgreportItem.getFieldType();
            if ("Integer".equals(fieldType) || "Date".equals(fieldType) || "Long".equals(fieldType)) {
                jSONObject.put("sorter", "true");
            }
            if (StringUtils.isNotBlank(onlCgreportItem.getFieldHref())) {
                String str = OnlSlotRender.f326e + onlCgreportItem.getFieldName();
                JSONObject jSONObject2 = new JSONObject();
                jSONObject2.put("customRender", str);
                jSONObject.put("scopedSlots", jSONObject2);
                JSONObject jSONObject3 = new JSONObject();
                jSONObject3.put("slotName", str);
                jSONObject3.put("href", onlCgreportItem.getFieldHref());
                jSONArray.add(jSONObject3);
            }
            String dictCode = onlCgreportItem.getDictCode();
            if (dictCode != null && !"".equals(dictCode)) {
                if (queryDict) {
                    hashMap2.put(onlCgreportItem.getFieldName(), queryColumnDict(onlCgreportItem.getDictCode(), null, null));
                    jSONObject.put("customRender", onlCgreportItem.getFieldName());
                } else {
                    jSONObject.put("dictCode", dictCode);
                }
            }
            jSONArray2.add(jSONObject);
        }
        if (queryDict) {
            hashMap.put("dictOptions", hashMap2);
        }
        hashMap.put("columns", jSONArray2);
        hashMap.put("fieldHrefSlots", jSONArray);
        hashMap.put("isGroupTitle", Boolean.valueOf(z));
        return hashMap;
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    public List<DictModel> queryColumnDict(String dictCode, JSONArray records, String fieldName) {
        List<DictModel> list = null;
        if (oConvertUtils.isNotEmpty(dictCode)) {
            if (dictCode.trim().toLowerCase().indexOf("select ") == 0 && (fieldName == null || records.size() > 0)) {
                String dictCode2 = dictCode.trim();
                int lastIndexOf = dictCode2.lastIndexOf(";");
                if (lastIndexOf == dictCode2.length() - 1) {
                    dictCode2 = dictCode2.substring(0, lastIndexOf);
                }
                this.sysBaseAPI.dictTableWhiteListCheckBySql(dictCode2);
                String str = "SELECT * FROM (" + dictCode2 + ") temp ";
                if (records != null) {
                    HashSet hashSet = new HashSet();
                    for (int i = 0; i < records.size(); i++) {
                        String string = records.getJSONObject(i).getString(fieldName);
                        if (StringUtils.isNotBlank(string)) {
                            hashSet.add(string);
                        }
                    }
                    str = str + "WHERE temp.value IN (" + (CgformUtil.f231C + StringUtils.join(hashSet, "','") + CgformUtil.f231C) + ")";
                }
                List<Map<String, Object>> executeSqlDict = ((OnlCgreportHeadMapper) this.baseMapper).executeSqlDict(str);
                if (executeSqlDict != null && executeSqlDict.size() != 0) {
                    list = JSON.parseArray(JSON.toJSONString(executeSqlDict), DictModel.class);
                }
            } else {
                list = this.sysBaseAPI.queryDictItemsByCode(dictCode);
            }
        }
        return list;
    }

    @Override // org.jeecg.modules.online.cgreport.service.IOnlCgreportHeadService
    public List<DictModel> queryColumnDictList(String dictCode, List<Map<String, Object>> records, String fieldName) {
        String m360a;
        List<DictModel> list = null;
        if (oConvertUtils.isNotEmpty(dictCode)) {
            String dictCode2 = dictCode.trim();
            if (dictCode2.toLowerCase().indexOf("select ") == 0 && (fieldName == null || records.size() > 0)) {
                if (dictCode2.endsWith(";")) {
                    dictCode2 = dictCode2.substring(0, dictCode2.length() - 1);
                }
                this.sysBaseAPI.dictTableWhiteListCheckBySql(dictCode2);
                QueryWrapper<?> queryWrapper = new QueryWrapper<>();
                if (records != null && records.size() < 100) {
                    HashSet hashSet = new HashSet();
                    for (int i = 0; i < records.size(); i++) {
                        Map<String, Object> map = records.get(i);
                        if (map != null && (m360a = CgformUtil.m360a(map, fieldName)) != null) {
                            hashSet.add(m360a.toString());
                        }
                    }
                    if (hashSet.size() > 0) {
                        queryWrapper.in("temp.value", hashSet);
                    }
                }
                list = ((OnlCgreportHeadMapper) getBaseMapper()).queryDictListBySql(dictCode2, queryWrapper);
            } else {
                list = this.sysBaseAPI.queryDictItemsByCode(dictCode2);
            }
        }
        return list;
    }
}
